{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "111\n"
     ]
    }
   ],
   "source": [
    "from pydantic import BaseModel\n",
    "class User(BaseModel):\n",
    "    name: str\n",
    "    email: str=111\n",
    "def func(info:User):\n",
    "    print(info[\"name\"])\n",
    "func({\"name\":\"111\",'abc':1})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "111\n"
     ]
    },
    {
     "ename": "TypeError",
     "evalue": "type.__new__(X): X is not a type object (str)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[41], line 12\u001b[0m\n\u001b[0;32m     10\u001b[0m         \u001b[39mprint\u001b[39m(\u001b[39m111\u001b[39m)\n\u001b[0;32m     11\u001b[0m         \u001b[39msuper\u001b[39m()\u001b[39m.\u001b[39m\u001b[39m__new__\u001b[39m(\u001b[39m*\u001b[39margs, \u001b[39m*\u001b[39m\u001b[39m*\u001b[39mkwargs)\n\u001b[1;32m---> 12\u001b[0m \u001b[39mclass\u001b[39;00m \u001b[39msingle2\u001b[39;00m(metaclass\u001b[39m=\u001b[39msingle):\n\u001b[0;32m     13\u001b[0m     \u001b[39mdef\u001b[39;00m \u001b[39m__init__\u001b[39m(\u001b[39mself\u001b[39m, name, age):\n\u001b[0;32m     14\u001b[0m         \u001b[39mprint\u001b[39m(name,age)\n",
      "Cell \u001b[1;32mIn[41], line 11\u001b[0m, in \u001b[0;36msingle.__new__\u001b[1;34m(cls, *args, **kwargs)\u001b[0m\n\u001b[0;32m      9\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39m__new__\u001b[39m(\u001b[39mcls\u001b[39m,\u001b[39m*\u001b[39margs, \u001b[39m*\u001b[39m\u001b[39m*\u001b[39mkwargs) :\n\u001b[0;32m     10\u001b[0m     \u001b[39mprint\u001b[39m(\u001b[39m111\u001b[39m)\n\u001b[1;32m---> 11\u001b[0m     \u001b[39msuper\u001b[39m()\u001b[39m.\u001b[39m\u001b[39m__new__\u001b[39m(\u001b[39m*\u001b[39margs, \u001b[39m*\u001b[39m\u001b[39m*\u001b[39mkwargs)\n",
      "\u001b[1;31mTypeError\u001b[0m: type.__new__(X): X is not a type object (str)"
     ]
    }
   ],
   "source": [
    "from typing import Any\n",
    "\n",
    "\n",
    "class single(type):\n",
    "    def __call__(self, *args, **kwargs) -> Any:\n",
    "        super().__call__(*args, **kwargs)\n",
    "   \n",
    "class single2(metaclass=single):\n",
    "    def __init__(self, name, age):\n",
    "        print(name,age)\n",
    "        self.name = name\n",
    "    def __new__(cls,*args, **kwargs) :\n",
    "        super().__new__(*args, **kwargs)\n",
    "  \n",
    "single2(\"John\", 20)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "chatglm2",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.10"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
